
//--------------------主页js效果---------------------------

//--------------------------主页的轮播图----------------------------------------
function Banner(classname){//主页轮播图函数
	this.content=getElementsByclassName(classname)[0];
	this.oBox=this.content.getElementsByTagName("ul")[0];
	this.aList=this.oBox.getElementsByTagName("ul");
	this.iHeight=parseInt(getStyle(this.aList[1],"height"));
	this.left=this.content.getElementsByTagName("div")[0];
	this.right=this.content.getElementsByTagName("div")[1];
	this.bottom=this.content.getElementsByTagName("div")[2];
	this.navWidth=parseInt(getStyle(this.bottom,"width"))
	this.aCur=this.bottom.getElementsByTagName("span");
	this.timer=null;
	this.index=0;
	this.turnoff=true;
	this.aImg=[
		"url(img/index-banner1.jpg)",
		"url(img/index-banner2.jpg)",
		"url(img/index-banner3.jpg)",
		"url(img/index-banner4.jpg)",
		"url(img/index-banner5.jpg)",
		"url(img/index-banner6.jpg)"
	]
	this.aUrl=[
		"http://www.wm18.com/shenghuojia/",
		"http://www.wm18.com/article.php?id=268",
		"http://www.wm18.com/article.php?id=244",
		"http://www.wm18.com/topic.php?topic_id=73",
		"http://www.wm18.com/topic.php?topic_id=70",
		"http://www.wm18.com/"
	]
	this.setPic();
	var _this=this;
	this.aCur[0].style.background="#e1472f";
	this.left.onclick=function(){
		_this.nextPicL();
	}
	this.right.onclick=function(){
		_this.nextPicR();
	}
	this.bottomSwitch();
	this.content.onmouseover=function(){
		_this.left.style.display=_this.right.style.display="block";
		clearInterval(_this.timer);
	}
	this.content.onmouseout=function(){
		_this.left.style.display=_this.right.style.display="none";
		_this.going();
	}
	_this.going();
}
Banner.prototype.nextPicL=function(){//实现向左切换
	var _this=this;
	if(_this.turnoff){
		_this.turnoff=false;
		_this.index--;
		if(_this.index<0){
			_this.index=5;
		}
		_this.move(_this.index);
	}else{
		return false;
	}
}
Banner.prototype.nextPicR=function(){//实现向右切换
	var _this=this;
	if(_this.turnoff){
		_this.turnoff=false;
		_this.index++;
		if(_this.index>5){
			_this.index=0;
		}
		_this.move(_this.index)
	}else{
		return false;
	}
}
Banner.prototype.bottomSwitch=function(){//实现底部点击切换
	var _this=this;
	for(var i=0;i<this.aCur.length;i++){
		this.aCur[i].index=i;
		this.aCur[i].onclick=function(){
			if(_this.turnoff){
				_this.turnoff=false;
				_this.index=this.index;
				_this.move(_this.index);
			}
		}
		this.aCur[i].onmouseover=function(){
			this.style.background="#e1472f";
		}
		this.aCur[i].onmouseout=function(){
			if(this!=_this.aCur[_this.index]){
				this.style.background="#fff";
			}	
		}
	}
}
Banner.prototype.setPic=function(){//给每个最内层li背景图以及位置
	for(var i=0;i<this.aList.length;i++){
		var aLi=this.aList[i].getElementsByTagName("li");
		for(var j=0;j<aLi.length;j++){
			aLi[j].style.backgroundImage=this.aImg[j];
			aLi[j].style.height=this.iHeight*10+"px";
			aLi[j].style.top=-(i*this.iHeight)+"px";
		}
	}
}
Banner.prototype.navcolor=function(){//实现下边小条随着index的变化，背景变化
	for(var i=0;i<this.aCur.length;i++){
		this.aCur[i].style.background="#fff";
	}
	this.aCur[this.index].style.background="#e1472f";
}
Banner.prototype.show=function(){//最内层li显示函数
	for(var i=0;i<this.aList.length;i++){
		var aLi=this.aList[i].getElementsByTagName("li");
		aLi[this.index].style.display="block";
	}
}
Banner.prototype.hide=function(){//最内层li隐藏的函数
	for(var i=0;i<this.aList.length;i++){
		var aLi=this.aList[i].getElementsByTagName("li");
		for(var j=0;j<aLi.length;j++){
			aLi[j].style.display="none";
		}
	}
}
Banner.prototype.move=function(){//实现运动效果的函数
	this.navcolor();
	this.hide();
	this.show();
	var _this=this;
	for(var i=0;i<this.aList.length;i++){
		(function(i){
			setTimeout(function(){
				startMove(16,_this.aList[i],{top:0,left:0},function(){
					if(i==_this.aList.length-1){
						_this.oBox.style.backgroundImage=_this.aImg[_this.index]
						for(var j=0;j<_this.aList.length;j++){
							_this.aList[j].style.top="-100%";
							_this.aList[j].style.left="3%";
						}
						_this.oBox.onclick=function(){
							window.open(_this.aUrl[_this.index]);
						}
						_this.turnoff=true;
					}else{
						return false;
					}	
				})
			},i*150)
		})(i)
	}
}
Banner.prototype.going=function(){//实现自动定时运动的函数，页面失去焦点时自动停止定时器
	clearInterval(this.timer);
	var _this=this;
	window.onblur=function(){
		clearInterval(_this.timer);
	}
	window.onfocus=function(){
		_this.going();
	}
	this.timer=setInterval(function(){
		_this.index++;
		if(_this.index>5){
			_this.index=0;
		}
		_this.move();
	},5000)
}
//-----------------------主页的轮播图结束-------------------------------------------
//------------------产品展示效果已经产品数据生成---------------------------------------------
function ProductMove(box,color){
	this.oBox=box;
	this.color=color;
	this.oDl=this.oBox.getElementsByTagName("dl")[0];
	this.oDd=this.oBox.getElementsByTagName("dd")[0];
	this.oDt=this.oBox.getElementsByTagName("dt")[0];
	this.oTitle=this.oDl.getElementsByTagName("h3")[0];
	this.oBrief=this.oDl.getElementsByTagName("p")[0];
	this.lookall=this.oDl.getElementsByTagName("p")[1];
	this.price=this.oDl.getElementsByTagName("b")[0];
	this.del=this.oDl.getElementsByTagName("del")[0];
	this.Sp=this.oDl.getElementsByTagName("span")[0];
	this.iWidth=parseInt(getStyle(this.oDl,"width"));
	var _this=this;
	this.oDl.onmouseover=function(){
		_this.over();
	}
	this.oDl.onmouseout=function(){
		_this.out();
	}
}
ProductMove.prototype.over=function(){
	var _this=this;
	var w=this.iWidth-10;
	this.oBrief.style.color="#fff";
	this.Sp.style.borderLeftColor=this.color;
	this.Sp.style.borderRightColor=this.color;
	this.oDt.style.background=this.color;
	startMove(20,_this.oDl,{width:w});
}
ProductMove.prototype.out=function(){
	var _this=this;
	this.oBrief.style.color="#888";
	this.Sp.style.borderLeftColor="#fff";
	this.Sp.style.borderRightColor="#fff";
	this.oDt.style.background="#fff";
	startMove(20,_this.oDl,{width:_this.iWidth});
}
ProductMove.prototype.write=function(){
	this.oTitle.innerHTML=this.data.title;
	this.oBrief.innerHTML=this.data.brief;
	this.lookall.innerHTML=this.data.lookall;
	this.price.innerHTML=this.data.price;
	this.del.innerHTML=this.data.del;
	this.oDd.style.backgroundImage="url("+this.data.img+")";
}
//------------------产品展示完成----------------------------------
//------------销售产品详情页动态效果以及数据生成----------------------------------------------
function Details(box){
	this.parent=box;
	this.child=$(".details",box)[0];
	this.banner=$(".details-head",box)[0];
	this.title=$(".details-title",box)[0];
	this.main=$(".details-main",box)[0];
	this.price=$(".price",box)[0];
	this.img=$(".details-img",box);
	this.close=$(".close",box)[0];
	this.cover=$("#cover2");
	this.add=$("#add-gouwuche");
	var _this=this;
	this.add.onclick=function(){
		actionTip();
	}
	this.parent.onclick=function(){
		_this.move();
	}
	this.close.onclick=function(ev){
		var e=ev||event;
		try{
			e.cancelBubble=true;
		}catch(n){
			e.stopPropagation();
		}
		_this.cover.style.display="none";
		_this.cover.style.opacity="0";
		_this.cover.style.filter="alpha(opacity:0)";
		startMove(10,_this.child,{width:382,height:227},function(){
			startMove(10,_this.child,{width:0,height:0});
		})
		return false;
	}
	this.child.onclick=function(ev){
		var e=ev||event;
		try{
			e.cancelBubble=true;
		}catch(n){
			e.stopPropagation();
		}
	}
}
Details.prototype.move=function(){
	var _this=this;
	var scrolltop=document.documentElement.scrollTop||document.body.scrollTop;
	_this.cover.style.top=scrolltop+"px";
	this.cover.style.display="block";
	startMove(8,_this.cover,{opacity:40});
	startMove(15,_this.child,{width:382,height:227},function(){
		startMove(15,_this.child,{height:695});
	})
}
Details.prototype.write=function(){
	this.title.innerHTML=this.data.title;
	this.main.innerHTML=this.data.brief;
	this.price.innerHTML=this.data.price;
	this.banner.style.backgroundImage="url("+this.data.banner+")";
	for(var i=0;i<this.data.img.length;i++){
		this.img[i].style.backgroundImage="url("+this.data.img[i]+")";
	}	
}

//---------------------------------------------------------------------------------
window.onload=function(){
	serach1();//搜索
	Testsign();//检测登录状态
	actionSerach();//搜索框效果
	actionBrandSeries();//左侧导航效果
	actionKefu();//右侧客服电话效果
	actionScroll();//右侧回到顶部效果
	var actionBanner = new Banner("banner-box");
	var P1=$(".recommend1")[0];
	var P2=$(".recommend2")[0];
	var P3=$(".recommend3")[0];
	var P4=$(".recommend4")[0];
	var aMimi=$(".productions",P1);
	var aWeinin=$(".productions",P2);
	var aJujia=$(".productions",P3);
	var aNews=$(".productions",P4);
	var aSale=$(".sale");
	for(var i=0;i<aMimi.length;i++){
		var oCase=new ProductMove(aMimi[i],"#eeafce");
		oCase.data=data.mimi[i];
		oCase.write();
	}
	for(var i=0;i<aWeinin.length;i++){
		var oCase=new ProductMove(aWeinin[i],"#97c86c");
		oCase.data=data.weinin[i];
		oCase.write();
	}
	for(var i=0;i<aJujia.length;i++){
		var oCase=new ProductMove(aJujia[i],"#8ccedc");
		oCase.data=data.jujia[i];
		oCase.write();
	}
	for(var i=0;i<aNews.length;i++){
		var oCase=new ProductMove(aNews[i],"");
		oCase.data=data.news[i];
		oCase.write();
		oCase.over=function(){
			var _this=this;
			var w=this.iWidth-10;
			this.Sp.style.borderLeftColor=this.color;
			this.Sp.style.borderRightColor=this.color;
			this.oDt.style.background=this.color;
			startMove(20,_this.oDl,{width:w});
		}
	}
	var oSale=$(".sale")[0];
	var ss=new Details(oSale);
	ss.data=data.details[0];
	ss.write();

}
